package classload;

import org.openjdk.jol.info.ClassLayout;

/**
 * 指针压缩测试
 */
public class JolSample {
    public static void main(String[] args) {
        ClassLayout layout = ClassLayout.parseInstance(new Object());
        System.out.println(layout.toPrintable());

        System.out.println();
        ClassLayout layout2 = ClassLayout.parseInstance(new int[]{});
        System.out.println(layout2.toPrintable());

        System.out.println();
        ClassLayout layout3 = ClassLayout.parseInstance(new A());
        System.out.println(layout3.toPrintable());
    }

    //  ‐XX:+UseCompressedOops  默认开启的压缩所有指针
    //  ‐XX:+UseCompressedClassPointers  默认开启的压缩对象头里的类型指针Klass  Pointer
    //  Oops  :  Ordinary  Object  Pointers
    public static class A {
        //8B  mark  word
        //4B  Klass  Pointer  如果关闭压缩‐XX:‐UseCompressedClassPointers或‐XX:‐UseCompressedOops，则占用8B
        int id; //4B
        String name = "asdasd";  //4B  如果关闭压缩‐XX:‐UseCompressedOops，则占用8B
        byte b; //1B
        Object o = new Object();  //4B  如果关闭压缩‐XX:‐UseCompressedOops，则占用8B
    }
}
